package com.nuoniu.sibanyun.controller.user;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.SysUser;
import com.nuoniu.sibanyun.entity.user.SysUserNote;
import com.nuoniu.sibanyun.service.user.ISysUserNoteService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户便签、笔记 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-09-03
 */
@RestController
@RequestMapping("/persons/note")
@Api(tags = "用户便签、笔记 前端控制器", value = "用户便签、笔记 前端控制器")
public class SysUserNoteController extends BaseController {

    @Autowired
    private ISysUserNoteService noteService;

    /**
     * 分页获取便签笔记
     * @author 小啊刚
     * @date 2020-09-03
     */
    @GetMapping("pageList")
    public HttpResult pageList(Page page, SysUserNote userNote) {
        return HttpResult.ok(noteService.pageList(page, userNote));
    }

    /**
     * 保存便签笔记
     * @author 小啊刚
     * @date 2020-09-03
     */
    @PostMapping("save")
    public HttpResult save(@RequestBody SysUserNote userNote) {
        UserInfo userInfo = UserThreadLocal.get();
        userNote.setUserId(userInfo.getUserId());
        noteService.saveOrUpdate(userNote);
        return HttpResult.ok();
    }

    /**
     * 删除便签笔记
     * @author 小啊刚
     * @date 2020-09-03
     */
    @PostMapping("delete")
    public HttpResult delete(@RequestBody List<String> ids) {
        for(String id : ids) {
            noteService.removeById(id);
        }
        return HttpResult.ok();
    }
}
